package com.umfwechat.util;

import java.util.HashMap;
import java.util.Map;

import com.umfwechat.common.constant.CommonConsts;

import net.sf.json.JSONObject;

/**
 * @ClassName BaseController
 * @desc 处理返回信息json串
 * @author liuchunyan
 * @date  2017-07-10
 * @version 1.0
 */

public class ResultJsonUtil {

	/**
	 * 返回成功json串
	 * 
	 * @param retCode 返回编码
	 * @param retMsg 返回信息
	 * @param paramMap 返回数据
	 * @return 返回信息json串
	 */
	public static String resultJson(String retCode, String retMsg, Map<String, Object> paramMap){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put(CommonConsts.RETCODE, retCode);
		resultMap.put(CommonConsts.RETMSG, retMsg);
		if(paramMap != null){
			for(String key : paramMap.keySet()){
				resultMap.put(key, paramMap.get(key));
			}
		}
		return JSONObject.fromObject(resultMap).toString();
	}
	
	/**
	 * 返回失败json串
	 * 
	 * @param retCode 返回编码
	 * @param retMsg 返回信息
	 * @return 返回信息json串
	 */
	public static String resultJson(String retCode, String retMsg){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put(CommonConsts.RETCODE, retCode);
		resultMap.put(CommonConsts.RETMSG, retMsg);
		return JSONObject.fromObject(resultMap).toString();
	}
}